package com.ruoyi.business.controller;

import java.util.List;

import com.ruoyi.business.utils.SnGenerateUtil;
import com.ruoyi.common.annotation.RepeatSubmit;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.JtProtocolTerms;
import com.ruoyi.business.service.IJtProtocolTermsService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 条款协议Controller
 * 
 * @author Alan Zhang
 * @date 2025-05-28
 */
@Controller
@RequestMapping("/business/terms")
public class JtProtocolTermsController extends BaseController
{
    private String prefix = "business/terms";

    @Autowired
    private IJtProtocolTermsService jtProtocolTermsService;

    @RequiresPermissions("business:terms:view")
    @GetMapping()
    public String terms()
    {
        return prefix + "/terms";
    }

    /**
     * 查询条款协议列表
     */
    @RequiresPermissions("business:terms:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(JtProtocolTerms jtProtocolTerms)
    {
        startPage();
        List<JtProtocolTerms> list = jtProtocolTermsService.selectJtProtocolTermsList(jtProtocolTerms);
        return getDataTable(list);
    }

    /**
     * 导出条款协议列表
     */
    @RequiresPermissions("business:terms:export")
    @Log(title = "条款协议", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(JtProtocolTerms jtProtocolTerms)
    {
        List<JtProtocolTerms> list = jtProtocolTermsService.selectJtProtocolTermsList(jtProtocolTerms);
        ExcelUtil<JtProtocolTerms> util = new ExcelUtil<JtProtocolTerms>(JtProtocolTerms.class);
        return util.exportExcel(list, "条款协议数据");
    }

    /**
     * 新增条款协议
     */
    @RequiresPermissions("business:terms:add")
    @GetMapping("/add")
    public String add(ModelMap mmap)
    {
        mmap.put("protocolNumber", SnGenerateUtil.jtProtocolNumber());
        return prefix + "/add";
    }

    /**
     * 新增保存条款协议
     */
    @RequiresPermissions("business:terms:add")
    @Log(title = "条款协议", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    @RepeatSubmit
    public AjaxResult addSave(JtProtocolTerms jtProtocolTerms)
    {
        return toAjax(jtProtocolTermsService.insertJtProtocolTerms(jtProtocolTerms));
    }

    /**
     * 修改条款协议
     */
    @RequiresPermissions("business:terms:edit")
    @GetMapping("/edit/{protocolId}")
    public String edit(@PathVariable("protocolId") Long protocolId, ModelMap mmap)
    {
        JtProtocolTerms jtProtocolTerms = jtProtocolTermsService.selectJtProtocolTermsByProtocolId(protocolId);
        mmap.put("jtProtocolTerms", jtProtocolTerms);
        return prefix + "/edit";
    }

    /**
     * 修改保存条款协议
     */
    @RequiresPermissions("business:terms:edit")
    @Log(title = "条款协议", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(JtProtocolTerms jtProtocolTerms)
    {
        return toAjax(jtProtocolTermsService.updateJtProtocolTerms(jtProtocolTerms));
    }

    /**
     * 删除条款协议
     */
    @RequiresPermissions("business:terms:remove")
    @Log(title = "条款协议", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(jtProtocolTermsService.deleteJtProtocolTermsByProtocolIds(ids));
    }
}
